<?php 
	include_once( dirname( __FILE__ )."/inc/conn.php" );
	include_once( dirname( __FILE__ )."/inc/function.php" );
	/* wk  统计 */

	$txtTimeBegin = isset($_GET['timebegin']) ? trim($_GET['timebegin']) : date('Y-m-d',strtotime('-1 day'));
	$txtTimeEnd = isset($_GET['timeend']) ? trim($_GET['timeend']) : date('Y-m-d');
	$where = '';
 
	 	
	if($txtTimeBegin && $txtTimeEnd){
		
		// $where =  " and  convert(varchar(10),WRITETIME,120) between '$txtTimeBegin' and '$txtTimeEnd' ";
		// $where =  " and  CAST(time AS TIME)  between '$txtTimeBegin' and '$txtTimeEnd' ";
		$where =  " and  time>='$txtTimeBegin' and time<='$txtTimeEnd' ";

	} 
 
	$dada = get_game_log(3,$where);
	$jianada = get_game_log(8,$where);
	$tj = array(
		'tzpoints' => $dada['tzpoints'] + $jianada['tzpoints'] ,
		'points' => $dada['points'] + $jianada['points'] ,
		'sy' => $dada['sy'] + $jianada['sy'] 
	);
	
function get_game_log($id,$where){
	global $db;
	$txt = "select sum(tzpoints) as tzpoints , (select sum( points) from game_day_static  where points > 0 and usertype = 0 and kindid = '$id' $where  ) as  points from game_day_static  where   usertype = 0 and kindid = '$id' $where";
	$sql = $db->query($txt);
 
	$dada = $db->fetch_array( $sql );
	if($dada['points'] <= 0 ){
		$dada['points'] = 0;
	}
	
	$dada['sy'] = $dada['tzpoints'] - $dada['points'];
	return $dada;
}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>本站盈亏</title>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
	<meta name="GENERATOR" content="MSHTML 6.00.3790.4275">
	<link rel="stylesheet" type="text/css" href="images/css_body.css">
	<link rel="stylesheet" type="text/css" href="images/window.css">
	<link rel="Stylesheet" type="text/css" href="images/jquery_ui.css" />
	<script type="text/javascript" src="images/jquery.js"></script> 
	<script type="text/javascript" src="images/jquery_ui.js"></script>
</head>
<body>
	<!-- 本站盈亏 -->
	<div class="bodytitle">
		<div class="bodytitleleft"></div>
		<div class="bodytitletxt">本站盈亏</div>
	</div>
	<div>
		<table class="tbtitle" width="99%" cellspacing="1" cellpadding="0" border="0" align="center" style="BACKGROUND: #F1F1F1;" >
			<tr bgcolor="#FFFFFF">
				<td> 
				    开始时间
				   <input id="txtTimeBegin" type="text" style="width:90px" value="<?php echo $txtTimeBegin; ?>" />&nbsp;
				   结束时间
				   <input id="txtTimeEnd" type="text" style="width:90px" value="<?php echo $txtTimeEnd; ?>" />
				  <input type="button" value="查询" id="btnSearch" class="btn-1"/>                 
			  </td>    
			 
			</tr>
		</table>
			
	<table class="tbtitle" width="99%" cellspacing="1" cellpadding="0" border="0" align="center" style="BACKGROUND: #F1F1F1;">
		<tr bgcolor=#F1F1F1>
			<td width="60px" >游戏输赢</td>
		<td align="center"><a class="edi" id='aGameLog28' href="user_gamelog.php?gametype=game28">蛋蛋28</a></td>
		<td align="center"><a class="edi" id='aGameLogcan28' href="user_gamelog.php?gametype=gamecan28">加拿大28</a></td>
		<td align="center">合计</td></tr>
		<tr bgcolor="#FFFFFF">
			<td align="center">总投注</td>
			<td align="center"><label id="lblGame_28"><?php echo $dada['tzpoints']; ?></label></td>
			<td align="center"><label id="lblGame_can28"><?php echo $jianada['tzpoints']; ?></label></td>
			<td  align="center"><label id="lblScore_total" style="color: blue;"><?php echo $tj['tzpoints']; ?></label> </td>
		</tr>
		<tr bgcolor="#FFFFFF">
			<td align="center">总赔付</td>
			<td align="center"><label id="lblGame_28"><?php echo $dada['points']; ?></label></td>
			<td align="center"><label id="lblGame_can28"><?php echo $jianada['points']; ?></label></td>
			<td  align="center"><label id="lblScore_total" style="color: blue;"><?php echo $tj['points']; ?></label> </td>
		</tr>
		<tr bgcolor="#FFFFFF">
			<td align="center">利润</td>
			<td align="center"><label id="lblGame_28"><?php echo $dada['sy']; ?></label></td>
			<td align="center"><label id="lblGame_can28"><?php echo $jianada['sy']; ?></label></td>
			<td  align="center"><label id="lblScore_total" style="color: blue;"><?php echo $tj['sy']; ?></label> </td>
		</tr>
	</table>
		<div class="fenyebar" id="PageInfo"></div>
	</div>
</body>
</html>
<script type= "text/javascript" language ="javascript">
 
    $(document).ready(function() {
    	InitDatePicker("txtTimeBegin");
        InitDatePicker("txtTimeEnd");
    
	});
    //**************************************************************************
  //查询
    $("#btnSearch").click(function(){
    	GetResult();
    });
    //取记录
    function GetResult()
    { 
        var data = GetData();
	 
		window.location.href='admin_index.php?key=wk&'+data;
     
    }
	 //取参数
    function GetData()
    {   
    	$("#tbResult tr:gt(0)").remove();
    	$("#PageInfo").html('');     
        var data = "action=get_rankprizelog";
      
        var DateBegin = $("#txtTimeBegin").val();
        var DateEnd = $("#txtTimeEnd").val();
         
        
            if(DateBegin != "")
            {
                if(!ValidDate(DateBegin))
                {
                    $("#txtTimeBegin").val("");
                }
                else
                {
                    data += "&timebegin=" + DateBegin;
                }
            }
            if(DateEnd != "")
            {
                if(!ValidDate(DateEnd))
                {
                    $("#txtTimeEnd").val("");
                }
                else
                {
                    data += "&timeend=" + DateEnd;
                }                
            }
        return data;
    }
    //****************************************************************************************
    //公共函数
    //初始化日期控件
    function InitDatePicker(o)
    {
		$("#" + o).datepicker({
            dateFormat: "yy-mm-dd",
            changeMonth: true,  //可以选择月份  
            changeYear: true,   //可以选择年份 
            dayNamesMin : ["日", "一", "二", "三", "四", "五", "六"], 
            firstDay : 1, 
            monthNamesShort: ["1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12"],
            yearRange: 'c-60:c+20'
        });  
    }
    //取得当前url参数
    function request(paras)
    {
        var url = location.href;  //获取当前url地址
        var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
        var paraObj = {}
        for (i=0; j=paraString[i]; i++){
            paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
        }
        var returnValue = paraObj[paras.toLowerCase()];
        if(typeof(returnValue)=="undefined"){
            return "";
        }else{
            return returnValue;
        }
    }
    //验证日期正确是否，如2012-06-22
	function ValidDate(str)
    { 
		 var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
		 if(r==null)return false; 
		 var d= new Date(r[1], r[3]-1, r[4]);
		 return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]); 
    }
    
</script>
